<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php
	function getPictureType($ext) {
		if ( preg_match('/jpg|jpeg/i', $ext) ) {
			return 'jpg';
		} else if ( preg_match('/png/i', $ext) ) {
			return 'png';
		} else if ( preg_match('/gif/i', $ext) ) {
			return 'gif';
		} else {
			return '';
		}
	}
	
	function resize($src_path, $dest_path, $file, $type, $width, $height){
		if ( $type == 'jpg' ) {
			$src = imagecreatefromjpeg($src_path.$file);
		} else if ( $type == 'png' ) {
			$src = imagecreatefrompng($src_path.$file);
		} else if ( $type == 'gif' ) {
			$src = imagecreatefromgif($src_path.$file);
		}
		if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {
			$newW = $oldW * ($width / $oldH);
			$newH = $height;
		} else {
			$newW = $width;
			$newH = $oldH * ($height / $oldW);
		}
		$new = imagecreatetruecolor($newW, $newH);
		imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);
		if ( $type == 'jpg' ) {
			imagejpeg($new, $dest_path.$file);
		} else if ( $type == 'png' ) {
			imagepng($new, $dest_path.$file);
		} else if ( $type == 'gif' ) {
			imagegif($new, $dest_path.$file);
		}
		imagedestroy($new);
		imagedestroy($src);
	}
?>